//
//  LoginTableViewController.m
//  ShowMe
//
//  Created by 123 on 2018/8/24.
//  Copyright © 2018年 nkl. All rights reserved.
//

#import "LoginVC.h"
#import "LoginView.h"
#import "RegisterViewController.h"
@interface LoginVC ()<loginViewDelegate>

@end

@implementation LoginVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
}

-(void)setUpUI{
    
    self.navigationController.navigationBar.hidden = YES;
    
    LoginView * loginView = [[[LoginView alloc] init] loadLoginViewFromXib];
    loginView.delegate = self;
    [self.view addSubview:loginView];
    [loginView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.view);
    }];
}
#pragma mark - 代理方法
-(void)registButtonClick{
    RegisterViewController * regVc = [[RegisterViewController alloc] init];
    [self.navigationController pushViewController:regVc animated:YES];
}

-(void)loginButtonClick:(NSString *)phoneNumber password:(NSString *)passWord{
    if (![PublicMethod isMobileNumber:phoneNumber]) {
        [ProgressHUD showSmallErroHUD:@"账号格式不正确"];
        return;
    }
    [DBUserTabelManager loginWithPhone:phoneNumber pwd:passWord result:^(BmobUser *user, NSError *error) {
        if (!error) {
            [ProgressHUD showSmallSuccessHUD:@"登陆成功"];
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
            NSLog(@"登录成功====用户信息%@\n",[UserConfig getSessionToken]);
        }else{
            if (error.code == 101) {
                [ProgressHUD showBigErroHUD:@"用户名或密码错误"];
            }else{
                [ProgressHUD showBigErroHUD:@"服务器出现问题,请稍后再试"];
                NSLog(@"登录失败====错误信息%ld\n",error.code);
            }
          
        }
    }];
}

-(void)forgetButtonClick{
    NSLog(@"忘记密码");
}



@end
